<template>
  <div>
    <router-link to="/Budget/addBudget"><div class="add_budget"></div></router-link>
    <table class="table ">
      <thead>
      <tr>
        <th>日期</th>
        <th>类型</th>
        <th>金额</th>
        <th></th>
      </tr>
      </thead>
      <tbody v-for="budget in budgets" :key="budget.id">
      <tr>
        <td><span class=" glyphicon glyphicon-time "></span> {{budget.time}}</td>
        <td>{{budget.type}}</td>
        <td>¥{{budget.amount}}</td>
        <td><router-link class="glyphicon glyphicon-pencil" v-bind:to="'/Budget/' + budget.id"></router-link></td>
      </tr>
      </tbody>
      <tfoot>
      <tr>
        <td>余额</td>
        <td colspan="4">{{sum}}</td>
      </tr>
      </tfoot>
    </table>
  </div>
</template>

<script>
export default {
  name: 'Center',
  data () {
    return {
      budgets: []
    }
  },
  computed: {
    sum: function () {
      return this.budgets.map(e => e.amount).reduce((a, b) => a + b)
    }
  },
  created () {
    this.$http.get('http://localhost:3000/budget')
      .then(function (response) {
        this.budgets = response.body
      })
  }
}
</script>

<style scoped>
  h1{
    font-size: 32px;
    font-weight: bold;
    padding: 15px;
    color: mediumaquamarine;
  }
  .add_budget{
    font-size: 16px;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
    border-radius: 5px;
    background-image: url('../../assets/icons/加号.png');
    background-repeat: no-repeat;
    background-position: 98% 50%;
    background-size: 30px 30px;
  }
  th{
    font-weight: normal;
    font-size: 20px;
    text-align: center;
  }
  td{
    font-weight: normal;
    font-size: 18px;
    background: white;
    border-bottom: #cccc 2px solid;
    text-align: center;
  }
  .btn{
    color: #66cdaa;
  }
  .table tfoot td,.table thead th{
    font-weight: normal;
    background: rgb(223,240,216);
  }
  .glyphicon{
    color: #66cdaa;
  }
</style>
